import os

import allure

from page.page_demo import PageDemo
from tool.get_driver import GetDriver
from tool.get_log import GetLogger

log = GetLogger.get_log()
module_name = str(os.path.basename(__file__)).split('.')[0]


@allure.epic("首页功能")
@allure.feature("首页底部tab栏测试")
class TestDebug():

    @classmethod
    def setup_class(cls):
        cls.driver = GetDriver.get_app_driver()
        cls.demo = PageDemo(cls.driver)
        cls.demo.page_demo_init()

    @classmethod
    def teardown_class(cls):
        GetDriver.quit_app_driver()

    @allure.story('进入首页测试用例')
    def test01_demo_image(self):
        with allure.step('1.进入小程序首页'):
            pass
        try:
            with allure.step('2.断言：判断首页是否进入成功'):
                pass
            assert self.demo.page_demo_fp_image_assert()
            el = self.demo.page_demo_fp_image_assert()[1]
            log.info('断言成功')
            self.demo.base_get_screenshot_as_file(module_name, '断言成功截图', image_el=el, msg_en='assert area')
        except AssertionError:
            self.demo.base_get_screenshot_as_file(module_name, '首页点击我的页面跳转失败')
            log.error('断言失败')
            raise
        finally:
            pass

    @allure.story('首页—我的tab跳转测试用例')
    def test02_demo(self):
        with allure.step('1.首页点击我的tab按钮'):
            pass
        self.demo.page_demo_click_mine()
        try:
            with allure.step('2.断言：判断页面是否有卡包元素'):
                pass
            assert self.demo.page_demo_click_mine_assert()
            log.info('断言成功')
            self.demo.base_get_screenshot_as_file(module_name, '断言成功截图')
        except AssertionError:
            self.demo.base_get_screenshot_as_file(module_name, '首页点击我的页面跳转失败')
            log.error('断言失败')
            raise
        finally:
            pass

    @allure.story('首页—断言失败的用例')
    def test03_demo_error(self):
        with allure.step('正在进行断言'):
            pass
        self.demo.base_get_screenshot_as_file(module_name, '错误断言示例截图')
        assert False
